package com.yaorange.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yaorange.entity.Book;
import com.yaorange.mapper.BookMapper;
import com.yaorange.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @description:
 * @company: yaorange
 * @author: Mr.Liu
 * @version: 1.0
 * @create: 2021-11-23 15:29:15
 */
@Service
@Transactional
public class BookServiceImpl implements BookService {

    @Autowired
    private BookMapper bookMapper;

    @Override
    public List<Book> findAll() {
        return bookMapper.selectAll();
    }

    @Override
    public PageInfo<Book> page(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Book> bookList = bookMapper.selectAll();
        PageInfo<Book> bookPageInfo = new PageInfo<>(bookList);
        return bookPageInfo;
    }

    @Override
    public Boolean add(Book book) {
        int rows = bookMapper.insert(book);
        if (rows > 0){
            return true;
        }
        return false;
    }

    @Override
    public Boolean update(Book book) {
        int rows = bookMapper.update(book);
        if (rows > 0){
            return true;
        }
        return false;
    }

    @Override
    public Boolean delete(Integer id) {
        int rows = bookMapper.delete(id);
        if (rows > 0){
            return true;
        }
        return false;
    }

    @Override
    public Book select(Integer id) {
        Book book = bookMapper.select(id);
        System.out.println(book);
        return book;
    }


}
